using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class SpawnController : MonoBehaviour {
	
	public GameObject minion;
	float timer, elapse;
	public List<GameObject> minions;

	public int goldInBank;

	bool spawnCD;

	// Use this for initialization
	void Start () {
		minions = new List<GameObject>();
		spawnCD = false;
		timer = 0f;
	}

//	public SpawnMinion(){
//		
//	}
	// Update is called once per frame
	void Update () {
		
		//elapse = Time.time;
		if (spawnCD && (Time.time - timer) >= 1.0f)
		{
			spawnCD = false;
			timer = Time.time;
		}
		if(!spawnCD){
			if (Input.GetKeyDown(KeyCode.UpArrow) || Input.GetKeyDown(KeyCode.T))
			{
				GameObject minionClone = (GameObject)Instantiate (minion, transform.position, Quaternion.identity);
				minionClone.GetComponent<Minion>().myPath = Minion.MinionPath.Top;
				minionClone.GetComponent<Minion>().SetID();
				minions.Add (minionClone);
				//Debug.Log("Shroom Spawned");
				timer = Time.time;

				spawnCD = true;
			}
			else if(Input.GetKeyDown(KeyCode.RightArrow) || Input.GetKeyDown(KeyCode.G)){
				GameObject minionClone = (GameObject)Instantiate (minion, transform.position, Quaternion.identity);
				minionClone.GetComponent<Minion>().myPath = Minion.MinionPath.Mid;
				minionClone.GetComponent<Minion>().SetID();
				minions.Add (minionClone);
				//Debug.Log("Shroom Spawned");
				timer = Time.time;
				
				spawnCD = true;
			}
			else if(Input.GetKeyDown(KeyCode.DownArrow) || Input.GetKeyDown(KeyCode.B)){
				GameObject minionClone = (GameObject)Instantiate (minion, transform.position, Quaternion.identity);
				minionClone.GetComponent<Minion>().myPath = Minion.MinionPath.Bot;
				minionClone.GetComponent<Minion>().SetID();
				minions.Add (minionClone);
				//Debug.Log("Shroom Spawned");
				timer = Time.time;
				
				spawnCD = true;
			}
		}
	}

	public void RemoveMinion(int ID)
	{
		foreach(GameObject g in minions)
		{
			if (g.GetComponent<Minion>().GetID() == this.GetComponent<Minion>().GetID())
			{
				minions.Remove(g);
				return;
			}
		}
	}
}